import os
import time
from datetime import datetime


class FileUtils(object):
    @staticmethod
    def get_dir_file_path(file_dir, file_type=None):
        if file_type is None:
            file_type = []
        file_path_list = []
        for dir_path, dir_name, file_list in os.walk(file_dir):
            for file in file_list:
                if file_type:
                    if os.path.splitext(file)[1] in file_type:
                        file_path_list.append(os.path.join(dir_path, file).replace("\\", "/"))
                else:
                    file_path_list.append(os.path.join(dir_path, file).replace("\\", "/"))
        return file_path_list

    @staticmethod
    def get_file_modified_time(file_path_list):
        file_info_list = []
        for file_path in file_path_list:
            modified_time = datetime.strptime(time.ctime(os.stat(file_path).st_mtime), "%a %b %d %H:%M:%S %Y")
            file_info_list.append({'path': file_path, 'modified_time': modified_time})
        return file_info_list

    @staticmethod
    def start_file(file_path):
        os.startfile(file_path)


file_utils = FileUtils()
